<?php
/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition End User License Agreement
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magento.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    Mage
 * @package     Mage_Customer
 * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license http://www.magento.com/license/enterprise-edition
 */

/**
 * API2 class for customer (admin)
 *
 * @category   Mage
 * @package    Mage_Customer
 * @author     Magento Core Team <core@magentocommerce.com>
 */
class ApiCenter_VendorsApi_Model_Api2_Account_Rest_Admin_V1 extends ApiCenter_VendorsApi_Model_Api2_Account_Rest
{
    const WEBSITEID ="1";
     /**
     * Login vendors
     *
     * @param array $data
     * @return string
     */
    protected function _multiUpdate($filteredData)
    {
        
            $data= $filteredData['account'];
          
            try {
                
          
            if($data['username']&&$data['password']){
                $vendor = Mage::getModel('vendors/vendor');
               // $session = Mage::getSingleton('vendors/session');
                $vendor->setWebsiteId(self::WEBSITEID);
                    try {
                        $this->_authenticate($vendor,$data);
                    } catch (Exception $e) {
                        $this->_critical("账号或密码错误!",400);
                    }
                 
                    $orderData=$vendor->getData();
                }else{
                    $this->_critical("账号或密码不能为空!",400);
                }  
			    $result['status']=1;
			    $result['info']=$orderData;
			 } catch (Exception $e) {
			    $result['status']=0;
			    $result['info']=$e->getMessage();
			 }
			  $this->_render($result);
    }
    /**
     * update info
     * 
     * */
    protected  function _update($filteredData){

        $vendor_id = $this->getRequest()->getParam("vendorid");
        try {
        if(isset($vendor_id)){
            $vendor = Mage::getModel('vendors/vendor')->load($vendor_id);
            if(!$vendor->getId()){
                $this->_critical("商家信息错误",400);
            }
			if($filteredData['new_password']){
			    $filteredData['password'] = $filteredData['confirmation'] = $filteredData['new_password'];
			}
            foreach($filteredData as $key=>$value)$vendor->setData($key,$value);
            
           $vendor->save();

        }
            $res['status']=1;
            $res['info']=$vendor->getData();
        
        } catch (Exception $e) {
            $res['status']=0;
            $res['info']=$e->getMessage();
        }
        
        $this->_render($res);
    }
}
